package week_09;

import java.util.*;

public class SlidingPuzzle_8_with_path_acw_179 {
    static Map<Integer, Integer> dist = new HashMap<>();
    static Map<Integer, Object[]> path = new HashMap<>();

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        int[] start = new int[9];
        for (int i = 0; i < 9; i++) {
            String item = input.next();
            if (item.equals("x")) {
                start[i] = 0;
            } else {
                start[i] = Integer.parseInt(item);
            }
        }

        int end = 123456780;
        dist.put(zip(start), 0);
        path.put(zip(start), null);
        Deque<Integer> deque = new LinkedList<>();
        deque.add(zip(start));
        int ans = -1;
        while (!deque.isEmpty()) {
            int top = deque.pop();
            int[] list = unzip(top);
            int pos = zeroIndex(list);
            // 向左移 <-
            if (pos != 0 && pos != 3 && pos != 6) insert(list, pos, pos - 1, deque, "l");
            // 向右移 ->
            if (pos != 2 && pos != 5 && pos != 8) insert(list, pos, pos + 1, deque, "r");
            // 向上移
            if (pos != 0 && pos != 1 && pos != 2) insert(list, pos, pos - 3, deque, "u");
            // 向下移
            if (pos != 6 && pos != 7 && pos != 8) insert(list, pos, pos + 3, deque, "d");
            if (top == end) {
                ans = top;
                break;
            }
        }
        StringBuilder sb = new StringBuilder();
        if (ans != -1) {
            while (ans != zip(start)) {
                sb.append(path.get(ans)[1]);
                ans = (Integer) path.get(ans)[0];
            }
            System.out.println(sb.reverse().toString());
        } else {
            System.out.println("unsolvable");
        }
    }

    private static void insert(int[] list, int pos1, int pos2, Deque<Integer> deque, String opt) {
        int old = zip(list);
        int depth = dist.get(old);
        swap(list, pos1, pos2);
        int zip = zip(list);
        if (!dist.containsKey(zip) || dist.get(zip) > depth + 1) {
            dist.put(zip, depth + 1);
            path.put(zip, new Object[]{old, opt});
            deque.offer(zip);
        }
        swap(list, pos2, pos1);
    }

    public static void swap(int[] arr, int i, int j) {
        if (i == j) return;
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

    private static int zeroIndex(int[] list) {
        for (int i = 0; i < 9; i++)
            if (list[i] == 0) return i;
        return -1;
    }

    public static int zip(int[] list) {
        int zip = 0;
        for (int i = 0; i < 9; i++) {
            zip = zip * 10 + list[i];
        }
        return zip;
    }

    public static int[] unzip(Integer zip) {
        int[] list = new int[9];
        for (int i = 8; i >= 0; i--) {
            list[i] = zip % 10;
            zip = zip / 10;
        }
        return list;
    }
}
